package com.example.bighomework.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.bighomework.R;

import org.checkerframework.checker.nullness.qual.NonNull;

public class DailyWeatherAdapter extends RecyclerView.Adapter<DailyWeatherAdapter.DailyViewHolder> {
    private String[] dates;
    private double[] maxTemperatures;
    private double[] minTemperatures;

    public DailyWeatherAdapter(String[] dates, double[] maxTemperatures, double[] minTemperatures) {
        this.dates = dates;
        this.maxTemperatures = maxTemperatures;
        this.minTemperatures = minTemperatures;
    }

    @NonNull
    @Override
    public DailyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_daily_weather, parent, false);
        return new DailyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull DailyViewHolder holder, int position) {
        holder.dateTextView.setText(dates[position]);
        holder.temperatureTextView.setText(minTemperatures[position] + "°C / " + maxTemperatures[position] + "°C");
    }

    @Override
    public int getItemCount() {
        return dates.length;
    }

    public class DailyViewHolder extends RecyclerView.ViewHolder {
        TextView dateTextView;
        TextView temperatureTextView;

        public DailyViewHolder(@NonNull View itemView) {
            super(itemView);
            dateTextView = itemView.findViewById(R.id.daily_date);
            temperatureTextView = itemView.findViewById(R.id.daily_min_max_temp);
        }
    }
}